version 14.2
set more off

***************************************************************************************************************************
* THIS ROUTINE GENERATES FIGURES V OF WASEEM (2020) ROLE OF WITHHOLDING ...
***************************************************************************************************************************

/* RAW TIME SERIES (WITHIN-FIRM CHANGES) MANUFACTURERS VS. IMPORTERS 1997-2003 */
*-------------------------------------------------------------------------------

use						"$project_data\STPAK_1996_2011_UBP_v1.dta", clear
keep                	if business_sts=="1" | business_sts=="2"
g						ind=real(substr(item_cd,1,4))
drop					if ind<1600
drop					if ind>=2500 & ind<2800
g						treat=business_sts=="1"
drop					if fy<=2003
drop					if fy>2010
drop					period
g						period=mofd(taxperiod)
qui						sum period
replace					period=period-r(min)+1
bys						period treat: g index=_n
g						double nexposale_ag=-exposale_ag
egen					double domsale2_ag=rowtotal(sale_ag nexposale_ag)
local					var="domsale2_ag"
g						logvar_real=log(`var')
qui						areg logvar_real i.period if treat==1, absorb(regnor)
g 						betahats=0
qui						sum period
local					nr=r(max)
forvalue				s=1/`nr' {
						cap replace betahats=_b[`s'.period] if period==`s' & treat==1
}
qui						areg logvar_real i.period if treat==0, absorb(regnor)
forvalue				s=1/`nr' {
						cap replace betahats=_b[`s'.period] if period==`s' & treat==0
}
#d						;
twoway  				(connected  betahats period if period>1 & index==1 & treat==1,sort lwidth(thick) lcolor(red) mcolor(red) msymbol(o))
						(connected  betahats period if period>1 & index==1 & treat==0,sort lwidth(thick) lcolor(midblue) mcolor(midblue) msymbol(o) lpattern(shortdash)),
						xtitle("Month of the Year") xscale(titlegap(*10))
						xlabel(1 "04" 13 "05" 25 "06" 37 "07" 49 "08" 61 "09" 73 "10" 85 "11")
						yscale(r(0))  yscale(titlegap(*10)) ytitle("Within-firm Mean of Log Sales") ylabel(-2(1)2)
						xline(13 25 37, lpatter(dash) lcolor(green))
						legend(region(style(none)) label(1 "Manufacturers") label(2 "Importers"))
						graphregion(fcolor(white) style(none) color(white) margin(0 0 0 2)) bgcolor(white);
graph 					export "$project_output\PanelDD_lndomsale_UBP_Placebo.eps", replace;
#d						cr

 /* DIFFERENCE-IN-DIFFERENCES MANUFACTURERS VS. IMPORTERS 1997-2003 */
*-------------------------------------------------------------------------------

use						"$project_data\STPAK_1996_2011_UBP_v1.dta", clear
keep                	if business_sts=="1" | business_sts=="2"
g						ind=real(substr(item_cd,1,4))
drop					if ind<1600
drop					if ind>=2500 & ind<2800
drop					if fy<=2003
drop					if fy>2010
drop					period
g						period=mofd(taxperiod)
qui						sum period
replace					period=period-r(min)+1
g						treat=business_sts=="1"
g						double nexposale_ag=-exposale_ag
egen					double domsale2_ag=rowtotal(sale_ag nexposale_ag)
bys						period: g index=_n
qui						sum period
local					nr=r(max)
forvalues				s=1/`nr' {
g						pdum`s'=period==`s'
}
forvalues				s=1/`nr' {
g						treat_pdum`s'=treat*pdum`s'
}
local					var="domsale2_ag"
g						logvar_real=log(`var')
qui						sum period
local					nr=r(max)
qui						areg logvar_real treat pdum2-pdum`nr' treat_pdum2-treat_pdum`nr', absorb(regnor) cluster(regnor)
g 						betahats=0
g						cil=0
g						cih=0
forvalue				s=1/`nr' {
						cap replace betahats=_b[treat_pdum`s'] if period==`s' 
						cap replace cil=_b[treat_pdum`s']-1.96*_se[treat_pdum`s'] if period==`s'
						cap replace cih=_b[treat_pdum`s']+1.96*_se[treat_pdum`s'] if period==`s'
}
#d						;
twoway  				(rarea cil cih period if period>1 & index==1,sort color(gs14))
						(connected  betahats period if period>1 & index==1,sort lwidth(thick) lcolor(red) mcolor(red) msymbol(o)),
						xtitle("Month of the Year") xscale(titlegap(*10))
						xlabel(1 "04" 13 "05" 25 "06" 37 "07" 49 "08" 61 "09" 73 "10" 85 "11")
						yscale(r(0))  yscale(titlegap(*10)) ytitle("Difference-in-differences Coefficient") ylabel(-2(1)2)
						xline(13 25 37, lpatter(dash) lcolor(green))
						legend(region(style(none)) label(1 "95% Confidence Interval") label(2 "Coefficient") order(2 1))
						graphregion(fcolor(white) style(none) color(white) margin(0 0 0 2)) bgcolor(white);
graph 					export "$project_output\DDP_`var'_UBP_Placebo.eps", replace;
#d						cr
